cat > update.sh <<'SH'
#!/usr/bin/env bash
set -e
branch=${1:-main}
git fetch origin
git switch "$branch"
git stash push -u -m "auto-stash $(date +%F_%T)" || true
git pull --rebase --recurse-submodules
git submodule update --init --recursive
git stash pop || true
echo "✅ Updated to latest on $branch"
SH
chmod +x update.sh
# 使用：
./update.sh main
